package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.liudecai.utils.common.CommonUtils;

import bean.RequestBean;

@WebServlet("/Request2MapServlet")
public class Request2MapServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public Request2MapServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
//		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");  //处理响应编码,否则在浏览器展现出乱码
		Object name = request.getParameter("username");
		System.out.println(name);
//		response.getWriter().append("Served at: ").append(request.getContextPath());
		
		//调用方法完成对表单数据封装到Bean中
		RequestBean bean = (RequestBean)CommonUtils.MyReqest2Bean(request, response, RequestBean.class);
		System.out.println(bean);
	    response.getWriter().write("name="+bean.getUsername()+"pass="+bean.getPassword()+"phone="+bean.getTelephone());
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
